package android.slc.module.sys.ui.dict.data

import android.slc.appbase.ui.AppView
import android.slc.appbase.ui.widget.grid.GridPaneUtils
import android.slc.box.commonlibrary.compat.SlcResourceUtils
import android.slc.box.core.property.DataChangeListener
import javafx.fxml.FXML
import javafx.scene.control.TextField
import javafx.scene.layout.GridPane

class DictDataEditView : AppView<DictDataEditVm>() {

    @FXML
    lateinit var propertyParentPane: GridPane

    @FXML
    lateinit var etDictLabel: TextField

    @FXML
    lateinit var etDictValue: TextField

    override fun onBindView() {
        super.onBindView()
        this.requireWindow().title = SlcResourceUtils.getString("app_label_dict_data_add")
        GridPaneUtils.formatGridColumn(propertyParentPane, 1)
        this.etDictLabel.textProperty().bindBidirectional(viewModel.dictLabelProperty)
        this.etDictValue.textProperty().bindBidirectional(viewModel.dictValueProperty)

        DictDataEditVd(boxContentPane, propertyParentPane, viewModel).initView()
    }

    override fun onRegisterLiveEvent() {
        super.onRegisterLiveEvent()
        this.viewModel.isEditProperty.addListener(DataChangeListener {
            this.requireWindow().title = if (this.viewModel.isEditProperty.value) {
                SlcResourceUtils.getString("app_label_dict_data_edit")
            } else {
                SlcResourceUtils.getString("app_label_dict_data_add")
            }
        })
    }

    override fun onBindViewLater() {
        super.onBindViewLater()
        this.viewModel.initVm()
    }
}